/*
* name;
*/

if (!String.prototype.format) {
    String.prototype.format = function () {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function (match, number) {
            return typeof args[number] !== "undefined" ? args[number] : match;
        });
    };
}  

var Utils = (function () {
    function Utils() {
        
    }
    Utils.prototype.isValid = function(value) {
        return value !== undefined && value !== null;
    };

     //适合单图点击有效果
     //{normal:"bao/bet1.png",pressed:"bao/onbet1.png"}
    Utils.prototype.registerButton = function (node,data) {

        if (this.isValid(node) === false) return; 
         
        node.on(Laya.Event.MOUSE_DOWN, this, function () {
             node.skin = data.pressed;
        });
        node.on(Laya.Event.MOUSE_UP, this, function () {
            node.skin = data.normal;
        });
        
        /** 
        node.on(Laya.Event.MOUSE_OUT, this, function () {
           
             node.skin = data.normal;
        });
        node.on(Laya.Event.MOUSE_OVER, this, function () {
           node.skin = data.pressed;
        });*/

        if (this.isValid(data.click))
            node.on(Laya.Event.CLICK, this, function(click){
                click.run()
            },[data.click]);
    }

    //适合单图点击有效果
    Utils.prototype.registerButtonEffect = function (node,data) {
        if (this.isValid(node) === false) return;
        node.on(Laya.Event.MOUSE_DOWN, this, function () {
            node.scale(0.9, 0.9)
        });
        node.on(Laya.Event.MOUSE_UP, this, function () {
            node.scale(1, 1)
        });
        node.on(Laya.Event.MOUSE_OUT, this, function () {
            node.scale(1, 1)
        });
        node.on(Laya.Event.MOUSE_OVER, this, function () {
            node.scale(0.9, 0.9)
        });

        if ( this.isValid(data) && this.isValid(data.click))
            node.on(Laya.Event.CLICK, this, function(click){
                click.run()
            },[data.click]);


    }
  

  
    Utils.getInstance = function(){
        return Utils.instance = Utils.instance || new Utils();
    }

    Utils.instance = null; 

    return Utils;
}());